$(function(){
	$('#ClName').blur(function(){
		var input=$(this).val();
		var regex=/^[А-ЯЇІ][А-ЯЇІ]*[а-яїі]*\s*[А-ЯЇІ]*[а-яїі]*\s*[А-ЯЇІ]*[а-яїі]*\s*$/;
		if (input.length<=2 || !regex.test(input)){
			$('#ClName').css("border","solid 2px red");
			$('#name-error').css("visibility", "visible");
		}
		else{
			$('#ClName').css("border","solid 2px #55ff55");
		}
	});
	$('#telNumber').blur(function(){
		var input=$(this).val();
		var regex=/^0[0-9]{9}$/;
		if (input.length<=2 || input[0]==input[0].toUpperCase|| !regex.test(input)){
			$('#tel-number-error').css("visibility", "visible");
			$('#telNumber').css("border","solid 2px red");
		}
		else{
			$('#telNumber').css("border","solid 2px #55ff55");
		}
	});
	$('#email').blur(function(){
		var input=$(this).val();
		var regex=/[A-Za-z][\w\.-]*@[\w\.-]{4,}$/;
		if (input.length<=2 || input[0]==input[0].toUpperCase|| !regex.test(input)){
			$('#email-error').css("visibility", "visible");
			$('#email').css("border","solid 2px red");
		}
		else{
			$('#email').css("border","solid 2px #55ff55");
		}
	});
	$('#content').ready(function(){
		var discsNum=parseInt($('#discs-numbrer').val());
		if (discsNum<1){
			$('#discs-table').hide();
			$('#basket-error').css("visibility","visible");
		}
	});
	$('#ClName').focus(function(){
		$('#name-error').css("visibility", "hidden");
		$('#form-error').css("visibility", "hidden");
	});
	$('#telNumber').focus(function(){
		$('#tel-number-error').css("visibility", "hidden");
		$('#form-error').css("visibility", "hidden");
	});
	$('#email').focus(function(){
		$('#email-error').css("visibility", "hidden");
		$('#form-error').css("visibility", "hidden");
	});
});

function validate(){
	if ($('#ClName').val()=="" || $('#telNumber').val()=="" || $('#email').val()=="" || $('#name-error').css('visibility')=='visible' || $('#tel-number-error').css('visibility')=='visible' || $('#email-error').css('visibility')=='visible' || $('#basket-error').css('visibility')=='visible'){
		$('#form-error').css("visibility", "visible");
		return false;
	}else{
		return true;
	};
};